﻿
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<script>
    var dictionaryData;
    var workFlowId = $.request("keyValue");
    var mark = $.request("mark");

    $(function () {
        initData();
    });

    //初始化控件
    function initControl() {

        if (mark == 'detail') {
            $('.form-control').prop('disabled', true);
        }

        var workFormIds = dictionaryData.F_WorkFormId;
        for (var i = 0; i < workFormIds.length; i++) {
            $("#F_WorkFormId").append("<option value='" + workFormIds[i].F_ItemCode + "'>" + workFormIds[i].F_ItemName + "</option>");
        }
    }

    //初始化字典数据
    function initDictionryData() {
        $.ajax({
            url: "/WorkFlowSetting/FlowManage/GetDictionaryItemsJson",
            dataType: "json",
            async: false,
            success: function (data) {
                dictionaryData = data;
            }
        });
    }

    //初始化数据
    function initData() {
        initDictionryData();
        initControl();

        if (mark == 'add') {
            return;
        }

        $.ajax({
            url: "/WorkFlowSetting/FlowManage/GetWorkFlowJson?keyValue=" + workFlowId,
            dataType: "json",
            async: false,
            success: function (data) {
                $("#F_WorkFlowName").val(data.F_WorkFlowName);
                $("#F_WorkFormId").val(data.F_WorkFormId);
            }
        });
    }

    //提交表单
    function submitForm() {

        if (!$('#form1').formValid()) {
            return false;
        }

        var $workFormId = $('#F_WorkFormId').val();

        if ($workFormId == null || $workFormId == '' || $workFormId.indexOf('请选择') >= 0) {
            $.modalAlert("请选中流程表单！", "warning");
            return false;
        }

        $.submitForm({
            url: "/WorkFlowSetting/FlowManage/SaveWorkFlow?keyValue=" + workFlowId,
            param: {
                'F_WorkFlowName': $('#F_WorkFlowName').val(),
                'F_WorkFormId': $('#F_WorkFormId').val()
            },
            success: function (result) {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        });

        return true;
    }

</script>

<form id="form1">
    <div style="padding-top: 20px; padding-left: 30px;">
        <table class="form">
            <tr>
                <td class="formValue" colspan="7"></td>
            </tr>
            <tr>
                <th class="formTitle">流程名称</th>
                <td class="formValue" colspan="2">
                    <input id="F_WorkFlowName" name="F_WorkFlowName" type="text" class="form-control required" />
                </td>
                <th class="formTitle">流程表单</th>
                <td class="formValue" colspan="2">
                    <select id="F_WorkFormId" name="F_WorkFormId" style="height: 15px;width: 88px;" class="form-control required">
                        <option>==请选择==</option>
                    </select>
                </td>

            </tr>

        </table>
    </div>
</form>
